package com.d3works.apps.base.service.batch;

import com.d3works.apps.base.db.Batch;
import com.d3works.apps.base.db.MailBatch;
import com.d3works.apps.base.db.repo.MailBatchRepository;
import com.d3works.apps.base.exceptions.BaseExceptionMessage;
import com.d3works.apps.base.service.administration.AbstractBatchService;
import com.d3works.db.Model;
import com.d3works.exception.D3worksException;
import com.d3works.exception.db.repo.TraceBackRepository;
import com.d3works.i18n.I18n;
import com.google.inject.Inject;

public class MailBatchService extends AbstractBatchService {

  @Inject protected BatchReminderMail batchReminderMail;

  @Override
  protected Class<? extends Model> getModelClass() {
    return MailBatch.class;
  }

  @Override
  public Batch run(Model batchModel) throws D3worksException {
    MailBatch mailBatch = (MailBatch) batchModel;

    switch (mailBatch.getActionSelect()) {
      case MailBatchRepository.ACTION_TIMESHEET_VALIDATION_REMINDER:
        return remindMail(mailBatch);
      default:
        throw new D3worksException(
            TraceBackRepository.CATEGORY_INCONSISTENCY,
            I18n.get(BaseExceptionMessage.BASE_BATCH_1),
            mailBatch.getActionSelect(),
            mailBatch.getCode());
    }
  }

  public Batch remindMail(MailBatch mailBatch) throws D3worksException {
    return this.run(mailBatch.getCode());
  }
}
